<%@ Language=VBScript %>
<%'------Begginging of FreeASPUploader Functions--------'%>
<% 

option explicit 
Response.Expires = -1
Server.ScriptTimeout = 600
' All communication must be in UTF-8, including the response back from the request
Session.CodePage  = 65001
%>
<!-- #include file="freeaspupload.asp" -->
<%

  Dim uploadsDirVar
  uploadsDirVar = "d:\webdata\AFND\www\diseases\uploader"
  'uploadsDirVar = Server.MapPath(".") & "\pops\"
  
  Dim Upload
  Set Upload = New FreeASPUpload
  
function TestEnvironment()
    Dim fso, fileName, testFile, streamTest
    TestEnvironment = ""
    Set fso = Server.CreateObject("Scripting.FileSystemObject")
    if not fso.FolderExists(uploadsDirVar) then
        TestEnvironment = "<B>Folder " & uploadsDirVar & " does not exist.</B><br>The value of your uploadsDirVar is incorrect. Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
        exit function
    end if
    fileName = uploadsDirVar & "\test.txt"
    on error resume next
    Set testFile = fso.CreateTextFile(fileName, true)
    If Err.Number<>0 then
        TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have write permissions.</B><br>The value of your uploadsDirVar is incorrect. Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
        exit function
    end if
    Err.Clear
    testFile.Close
    fso.DeleteFile(fileName)
    If Err.Number<>0 then
        TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have delete permissions</B>, although it does have write permissions.<br>Change the permissions for IUSR_<I>computername</I> on this folder."
        exit function
    end if
    Err.Clear
    Set streamTest = Server.CreateObject("ADODB.Stream")
    If Err.Number<>0 then
        TestEnvironment = "<B>The ADODB object <I>Stream</I> is not available in your server.</B><br>Check the Requirements page for information about upgrading your ADODB libraries."
        exit function
    end if
    Set streamTest = Nothing
end function

function SaveFiles
    Dim fileName, fileSize

    Upload.Save(uploadsDirVar)
	
	Dim dis_id
	dis_id = Upload.Form("dis_id")
	Dim dis_name
	dis_name = Upload.Form("dis_name")
	
		' If something fails inside the script, but the exception is handled
	If Err.Number<>0 then Exit function
   
			'if Upload.UploadedFiles(fileKey).Length < 200000 then			
			
				Dim fso
				Set fso = Server.CreateObject("Scripting.FileSystemObject")
				Dim ext
				ext = fso.GetExtensionName(uploadsDirVar & "\" & Upload.UploadedFiles("attach1").fileName)
				Dim endfilename
				endfilename = GetFileName(uploadsDirVar,dis_id & " " & dis_name & "." & ext)
    			Dim openfile
				set openfile = fso.GetFile(uploadsDirVar & "\" & Upload.UploadedFiles("attach1").fileName)
					'if (fso.FileExists(uploadsDirVar & "\" & dis_id & " " & dis_name & "." & ext))=true Then 
    					'fso.DeleteFile(uploadsDirVar & "\" & dis_id & " " & dis_name & "." & ext)
						'openfile.name = dis_id & " " & dis_name & "." & ext
					'else
						openfile.name = endfilename
    				'End If
				set openfile = nothing 
    			set fso = nothing
			'else
				'set fso = Server.CreateObject("Scripting.FileSystemObject")
				'if fso.FileExists(uploadsDirVar & "\" & Upload.UploadedFiles(fileKey).FileName) then
					'fso.DeleteFile(uploadsDirVar & "\" & Upload.UploadedFiles(fileKey).FileName)
	    			'set fso = nothing
					'SaveFiles = SaveFiles & "<p>File is too large!</p>"
				'End if
				SaveFiles = endfilename

end function

function ValRawData
'//GETTING RAW DATA FROM EXCEL FILE				
Dim objConn
Dim objRS
Dim strSQL
Dim i

Err.Clear
on error resume next

set objConn = Server.CreateObject("ADODB.Connection")

'//Web Host (allow just .xls file extensions) // WebHost does not have .xlsx Driver
'objConn.Open "DRIVER={Microsoft Excel Driver (*.xls)}; IMEX=1; HDR=YES; "&_
'"Excel 8.0; DBQ=" & uploadsDirVar & nameoffile & "; "

'//Local Host
'if using xslx (Excel 2007) use this instead:
objConn.Open "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};"&_
"DBQ=" & uploadsDirVar & "\" & nameoffile & "; IMEX=1; "

If Err.Number <> 0 Then
	Response.Write("<div id='tryagain'><p><b>File was not uploaded!</b></p><p>Sorry, unexpected error! Try again!</p></div>")
	Exit Function
End If
strSQL = ""
strSQL = "SELECT * FROM RawData"
Set objRS = objConn.Execute(strSQL)
If Err.Number <> 0 Then
	Response.Write("<div id='tryagain'><p><b>File was not uploaded!</b></p><p>You must use the template file &quot;KIR_Raw_Data.xls&quot;. You must not copy and paste the content to another file.</p><p>Please, make sure you are using the correct file and try again!</p></div>")
	Exit Function
End If
objRS.Close
objConn.Close
Set objRS=Nothing
Set objConn=Nothing

set objConn = Server.CreateObject("ADODB.Connection")
'//Web Host (allow just .xls file extensions) // WebHost does not have .xlsx Driver
'objConn.Open "DRIVER={Microsoft Excel Driver (*.xls)}; IMEX=1; HDR=YES; "&_
'"Excel 8.0; DBQ=" & uploadsDirVar & nameoffile & "; "
'//Local Host
'if using xslx (Excel 2007) use this instead:
objConn.Open "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};"&_
"DBQ=" & uploadsDirVar & "\" & nameoffile & "; IMEX=1; "

strSQL = ""
strSQL = "SELECT * FROM RawData"
Set objRS = objConn.Execute(strSQL)

If Err.Number <> 0 Then
	Response.Write("<div id='tryagain'><p><b>File was not uploaded!</b></p><p>You must use the template file &quot;KIR_Raw_Data.xls&quot;. You must not copy and paste the content to another file.</p><p>Please, make sure you are using the correct file and try again!</p></div>")
	Exit Function
End If

Dim headers_array(26)
headers_array(0) = "Sample"
headers_array(1) = "Sex"
headers_array(2) = "2DL1"
headers_array(3) = "2DL2"
headers_array(4) = "2DL3"
headers_array(5) = "2DL4"
headers_array(6) = "2DL5"
headers_array(7) = "2DP1"
headers_array(8) = "2DS1"
headers_array(9) = "2DS2"
headers_array(10) = "2DS3"
headers_array(11) = "2DS4"
headers_array(12) = "2DS5"
headers_array(13) = "3DL1"
headers_array(14) = "3DL2"
headers_array(15) = "3DL3"
headers_array(16) = "3DP1"
headers_array(17) = "3DS1"
headers_array(18) = "Bw4"
headers_array(19) = "(80)T"
headers_array(20) = "(80)I"
headers_array(21) = "Bw6"
headers_array(22) = "C1"
headers_array(23) = "C2"
headers_array(24) = "A3"
headers_array(25) = "A11"
headers_array(26) = "Cw4"

For i=0 To UBound(headers_array)
	If headers_array(i) <> objRS.Fields(i).Name Then
		 objRS.Close
 		 objConn.Close
 		 Set objRS=Nothing
 		 Set objConn=Nothing
		 Response.Write("<div id='tryagain'><p>File was not uploaded! Please, check <span style='color:red'>&quot;<b>" & headers_array(i) & "&quot;</b></span> field header. All headers must be same as the original template.</p><p><b>Try Again!</b></p></div>")
		 Exit Function
	End If
Next

For i=0 to objRS.Fields.Count-1
	If IsNull(objRS.Fields(i).Value) Then
		Response.Write("<div id='tryagain'><p>File was not uploaded! Value of <b>Line ID=1</b> on <span style='color:red'>&quot;<b>" & headers_array(i) & "&quot;</b></span> field is blank! Check &quot;Instructions&quot; worksheet for more information.</p><p><b>Try Again!</b></p></div>")
		objRS.Close
 		objConn.Close
 		Set objRS=Nothing
 		Set objConn=Nothing
		Exit Function
	End If
Next

objRS.MoveNext

Dim y
y = 1

Do Until objRS.EOF
	If IsNull(objRS.Fields(0).Value) Then
		Do Until objRS.EOF
			For i=0 to objRS.Fields.Count-1
				If objRS.Fields(i).Value <> "" Then
					Response.Write("<div id='tryagain'><p>File was not uploaded! Value of <b>Line ID=" & y+1 & "</b> on <span style='color:red'>&quot;<b>" & headers_array(i) & "&quot;</b></span> field is incorrect! Check &quot;Instrunctions&quot; worksheet for more information.</p><p><b>Try Again!</b></p></div>")
					Exit Function
				End If
			Next
			objRS.MoveNext
		Loop
	Else
		For i=1 to objRS.Fields.Count-1
			If IsNull(objRS.Fields(i).Value) Then
				Response.Write("<div id='tryagain'><p>File was not uploaded! Value of <b>Line ID=" & y+1 & "</b> on <span style='color:red'>&quot;<b>" & headers_array(i) & "&quot;</b></span> field is incorrect! Check &quot;Instrunctions&quot; worksheet for more information.</p><p><b>Try Again!</b></p></div>")
				Exit Function
			End If
		Next
		y = y + 1
		objRS.MoveNext
	End If
Loop

Dim sample, sex, gene, x
objRS.MoveFirst
For x=1 to y
		sample = LCase(Trim(CStr(objRS.Fields(0).Value)))
		If sample <> "patient" AND sample <> "special control" AND sample <> "control" Then
			Response.Write("<div id='tryagain'><p>File was not uploaded! Invalid value in <b>Line ID="& x &"</b> on <span style='color:red'><b>&quot;Sample&quot;</b></span> field! Valid values are &quot;control&quot;, &quot;special control&quot; and &quot;patient&quot;.</p><p><b>Try Again!</b></p></div>")
			Exit Function
		End If
		sex = LCase(Trim(CStr(objRS.Fields(1).Value)))
		If sex <> "f" AND sex <> "m" AND sex <> "nd" Then
			Response.Write("<div id='tryagain'><p>File was not uploaded! Invalid value in <b>Line ID="& x &"</b> on <span style='color:red'><b>&quot;Sex&quot;</b></span> field! Valid values are &quot;f&quot;, &quot;m&quot; and &quot;nd&quot; (no data).</p><p><b>Try Again!</b></p></div>")
			Exit Function
		End If
		For i=2 to 17
		gene = Mid(LCase(Trim(CStr(objRS.Fields(i).Value))),1,3)
		If gene <> "1" AND gene <> "0" AND gene <> "nd" AND gene <> "kir" Then
			Response.Write("<div id='tryagain'><p>File was not uploaded! Invalid value in <b>Line ID="& x &"</b> on <span style='color:red'><b>&quot;" & headers_array(i) & "&quot;</b></span> field! Valid values are &quot;1&quot;, &quot;0&quot;, &quot;nd&quot; (no data) and allele name beginning with &quot;KIR&quot; prefix.</p><p><b>Try Again!</b></p></div>")
			Exit Function
		End If
		Next
		For i=18 to objRS.Fields.Count-1
		gene = Mid(LCase(Trim(CStr(objRS.Fields(i).Value))),1,3)
		If gene <> "1" AND gene <> "0" AND gene <> "nd" AND gene <> "hla" Then
			Response.Write("<div id='tryagain'><p>File was not uploaded! Invalid value in <b>Line ID="& x &"</b> on <span style='color:red'><b>&quot;" & headers_array(i) & "&quot;</b></span> field! Valid values are &quot;1&quot;, &quot;0&quot;, &quot;nd&quot; (no data) and allele name beginning with &quot;HLA&quot; prefix.</p><p><b>Try Again!</b></p></div>")
			Exit Function
		End If
		Next		
	objRS.MoveNext
Next

ValRawData = true

objRS.Close
objConn.Close
Set objRS=Nothing
Set objConn=Nothing

end function

function SaveVars
	
	SaveVars = ""
	Dim counter
	counter = Upload.Form("counter")
	SaveVars = SaveVars & "<input type='hidden' name='counter' id='counter' value='" & counter & "' />"
	
	'//DEMOGRAPHIC VARIABLES		
	Dim dis_id
	dis_id = Upload.Form("dis_id")
	Dim mesh_id
	mesh_id = Upload.Form("mesh_id")
	Dim dis_name
	dis_name = Upload.Form("dis_name")
	Dim dis_polyreg
	dis_polyreg = "KIR"
	Dim dis_city
	dis_city = Upload.Form("dis_city")
	Dim dis_region
	dis_region = Upload.Form("dis_region")
	Dim dis_country
	dis_country = Upload.Form("dis_country")
	Dim dis_cont
	dis_cont = Upload.Form("dis_cont")
	Dim pop_lat1_deg
	pop_lat1_deg = Upload.Form("pop_lat1_deg")
	Dim pop_lat1_min
	pop_lat1_min = Upload.Form("pop_lat1_min")
	Dim pop_lat1_card
	pop_lat1_card = Upload.Form("pop_lat1_card")
	Dim pop_long1_deg
	pop_long1_deg = Upload.Form("pop_long1_deg")
	Dim pop_long1_min
	pop_long1_min = Upload.Form("pop_long1_min")
	Dim pop_long1_card
	pop_long1_card = Upload.Form("pop_long1_card")
	Dim dis_eth
	dis_eth = Upload.Form("dis_eth")
	Dim dis_sample_size_ctrls
	dis_sample_size_ctrls = Upload.Form("dis_sample_size_ctrls")
	Dim dis_sample_size_spec_ctrls
	dis_sample_size_spec_ctrls = Upload.Form("dis_sample_size_spec_ctrls")
	Dim	dis_sample_size_patients
	dis_sample_size_patients = Upload.Form("dis_sample_size_patients")
	Dim pop_source_ctrls
	pop_source_ctrls = Upload.Form("pop_source_ctrls")
	Dim dis_extra_notes
	dis_extra_notes = Upload.Form("dis_extra_notes")
	Dim dis_corr_auth
	dis_corr_auth = Upload.Form("dis_corr_auth")
	Dim dis_email
	dis_email = Upload.Form("dis_email")
	Dim dis_authors
	dis_authors = Upload.Form("dis_authors")
	Dim dis_year
	dis_year = Upload.Form("dis_year")
	Dim afnd_id
	afnd_id = Upload.Form("afnd_id")
	Dim afnd_name
	afnd_name = Upload.Form("afnd_name")
	Dim dis_pmid
	dis_pmid = Upload.Form("dis_pmid")
	If dis_pmid = "" Then
		dis_pmid = "0"
	End If
	Dim dis_status
	dis_status = "P"

    SaveVars = SaveVars & "<input type='hidden' name='dis_id' id='dis_id' value='" & dis_id & "' />"
    SaveVars = SaveVars & "<input type='hidden' name='mesh_id' id='mesh_id' value='" & mesh_id & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='dis_name' id='dis_name' value='" & dis_name & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='dis_polyreg' id='dis_polyreg' value='" & dis_polyreg & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='dis_city' id='dis_city' value='" & dis_city & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='dis_region' id='dis_region' value='" & dis_region & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='dis_country' id='dis_country' value='" & dis_country & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='dis_cont' id='dis_cont' value='" & dis_cont & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='pop_lat1_deg' id='pop_lat1_deg' value='" & pop_lat1_deg & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='pop_lat1_min' id='pop_lat1_min' value='" & pop_lat1_min & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='pop_lat1_card' id='pop_lat1_card' value='" & pop_lat1_card & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='pop_long1_deg' id='pop_long1_deg' value='" & pop_long1_deg & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='pop_long1_min' id='pop_long1_min' value='" & pop_long1_min & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='pop_long1_card' id='pop_long1_card' value='" & pop_long1_card & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='dis_eth' id='dis_eth' value='" & dis_eth & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='dis_sample_size_ctrls' id='dis_sample_size_ctrls' value='" & dis_sample_size_ctrls & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='dis_sample_size_spec_ctrls' id='dis_sample_size_spec_ctrls' value='" & dis_sample_size_spec_ctrls & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='dis_sample_size_patients' id='dis_sample_size_patients' value='" & dis_sample_size_patients & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='pop_source_ctrls' id='pop_source_ctrls' value='" & pop_source_ctrls & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='dis_corr_auth' id='dis_corr_auth' value='" & dis_corr_auth & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='dis_email' id='dis_email' value='" & dis_email & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='dis_authors' id='dis_authors' value='" & dis_authors & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='dis_year' id='dis_year' value='" & dis_year & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='afnd_id' id='afnd_id' value='" & afnd_id & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='afnd_name' id='afnd_name' value='" & afnd_name & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='dis_pmid' id='dis_pmid' value='" & dis_pmid & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='dis_extra_notes' id='dis_extra_notes' value='" & dis_extra_notes & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='dis_status' id='dis_status' value='" & dis_status & "' />"

	'//FREQUENCY VARIABLES

  Dim haplogroup_array
 redim haplogroup_array(counter)
  Dim g2DL1_array
redim g2DL1_array(counter)
  Dim g2DL2_array
redim g2DL2_array(counter)
  Dim g2DL3_array
redim g2DL3_array(counter)
  Dim g2DL4_array
redim g2DL4_array(counter)
  Dim g2DL5_array
redim g2DL5_array(counter)
  Dim g2DP1_array
redim g2DP1_array(counter)
  Dim g2DS1_array
redim g2DS1_array(counter)
  Dim g2DS2_array
redim g2DS2_array(counter)
  Dim g2DS3_array
redim g2DS3_array(counter)
  Dim g2DS4_array
redim g2DS4_array(counter)
  Dim g2DS5_array
redim g2DS5_array(counter)
  Dim g3DL1_array
redim g3DL1_array(counter)
  Dim g3DL2_array
redim g3DL2_array(counter)
  Dim g3DL3_array
redim g3DL3_array(counter)
  Dim g3DP1_array
redim g3DP1_array(counter)
  Dim g3DS1_array
redim g3DS1_array(counter)
  Dim gA3_array
redim gA3_array(counter)
  Dim gA11_array
redim gA11_array(counter)
  Dim gBw4_array
redim gBw4_array(counter)
  Dim gBw480i_array
redim gBw480i_array(counter)
  Dim gC1_array
redim gC1_array(counter)
  Dim gC2_array
redim gC2_array(counter)
  Dim gfc_array
redim gfc_array(counter)
  Dim gfsc_array
redim gfsc_array(counter)
  Dim gfp_array
redim gfp_array(counter)
  Dim odds_array
redim odds_array(counter)
  Dim pvalue_array
redim pvalue_array(counter)
  Dim stat_array
redim stat_array(counter)
  Dim corr_array
redim corr_array(counter)



Dim i
For i = 1 to counter

	haplogroup_array(i) = Upload.Form("haplogroup" & i)
	g2DL1_array(i) = Upload.Form("g2DL1_" & i)
	g2DL2_array(i) = Upload.Form("g2DL2_" & i)
	g2DL3_array(i) = Upload.Form("g2DL3_" & i)
	g2DL4_array(i) = Upload.Form("g2DL4_" & i)
	g2DL5_array(i) = Upload.Form("g2DL5_" & i)
	g2DP1_array(i) = Upload.Form("g2DP1_" & i)
	g2DS1_array(i) = Upload.Form("g2DS1_" & i)
	g2DS2_array(i) = Upload.Form("g2DS2_" & i)
	g2DS3_array(i) = Upload.Form("g2DS3_" & i)
	g2DS4_array(i) = Upload.Form("g2DS4_" & i)
	g2DS5_array(i) = Upload.Form("g2DS5_" & i)
	g3DL1_array(i) = Upload.Form("g3DL1_" & i)
	g3DL2_array(i) = Upload.Form("g3DL2_" & i)
	g3DL3_array(i) = Upload.Form("g3DL3_" & i)
	g3DP1_array(i) = Upload.Form("g3DP1_" & i)
	g3DS1_array(i) = Upload.Form("g3DS1_" & i)
	gA3_array(i) = Upload.Form("gA3_" & i)
	gA11_array(i) = Upload.Form("gA11_" & i)
	gBw4_array(i) = Upload.Form("gBw4_" & i)
	gBw480i_array(i) = Upload.Form("gBw480i_" & i)
	gC1_array(i) = Upload.Form("gC1_" & i)
	gC2_array(i) = Upload.Form("gC2_" & i)
	gfc_array(i) = Upload.Form("gfc" & i)
	gfsc_array(i) = Upload.Form("gfsc" & i)
	gfp_array(i) = Upload.Form("gfp" & i)
	odds_array(i) = Upload.Form("odds" & i)
	pvalue_array(i) = Upload.Form("pvalue" & i)
	stat_array(i) = Upload.Form("stat" & i)
	corr_array(i) = Upload.Form("corr" & i)
	
	SaveVars = SaveVars & "<input type='hidden' name='haplogroup" & i & "' id='haplogroup" & i & "' value='" & haplogroup_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='g2DL1_" & i & "' id='g2DL1_" & i & "' value='" & g2DL1_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='g2DL2_" & i & "' id='g2DL2_" & i & "' value='" & g2DL2_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='g2DL3_" & i & "' id='g2DL3_" & i & "' value='" & g2DL3_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='g2DL4_" & i & "' id='g2DL4_" & i & "' value='" & g2DL4_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='g2DL5_" & i & "' id='g2DL5_" & i & "' value='" & g2DL5_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='g2DP1_" & i & "' id='g2DP1_" & i & "' value='" & g2DP1_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='g2DS1_" & i & "' id='g2DS1_" & i & "' value='" & g2DS1_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='g2DS2_" & i & "' id='g2DS2_" & i & "' value='" & g2DS2_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='g2DS3_" & i & "' id='g2DS3_" & i & "' value='" & g2DS3_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='g2DS4_" & i & "' id='g2DS4_" & i & "' value='" & g2DS4_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='g2DS5_" & i & "' id='g2DS5_" & i & "' value='" & g2DS5_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='g3DL1_" & i & "' id='g3DL1_" & i & "' value='" & g3DL1_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='g3DL2_" & i & "' id='g3DL2_" & i & "' value='" & g3DL2_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='g3DL3_" & i & "' id='g3DL3_" & i & "' value='" & g3DL3_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='g3DP1_" & i & "' id='g3DP1_" & i & "' value='" & g3DP1_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='g3DS1_" & i & "' id='g3DS1_" & i & "' value='" & g3DS1_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='gA3_" & i & "' id='gA3_" & i & "' value='" & gA3_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='gA11_" & i & "' id='gA11_" & i & "' value='" & gA11_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='gBw4_" & i & "' id='gBw4_" & i & "' value='" & gBw4_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='gBw480i_" & i & "' id='gBw480i_" & i & "' value='" & gBw480i_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='gC1_" & i & "' id='gC1_" & i & "' value='" & gC1_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='gC2_" & i & "' id='gC2_" & i & "' value='" & gC2_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='gfc" & i & "' id='gfc" & i & "' value='" & gfc_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='gfsc" & i & "' id='gfsc" & i & "' value='" & gfsc_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='gfp" & i & "' id='gfp" & i & "' value='" & gfp_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='odds" & i & "' id='odds" & i & "' value='" & odds_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='pvalue" & i & "' id='pvalue" & i & "' value='" & pvalue_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='stat" & i & "' id='stat" & i & "' value='" & stat_array(i) & "' />"
	SaveVars = SaveVars & "<input type='hidden' name='corr" & i & "' id='corr" & i & "' value='" & corr_array(i) & "' />"
Next

	Dim pnt_assoc
	pnt_assoc = Upload.Form("pnt_assoc")
	SaveVars = SaveVars & "<input type='hidden' name='pnt_assoc' id='pnt_assoc' value='" & pnt_assoc & "' />"

end function


%>

<%'------End of FreeASPUploader Functions--------'%>

<%'------Beginning of WebPage--------'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%
'#-------------------------------------------------------------------------------#
'#  Description:       KIR-Add a disease association study.                      #
'#                     Code:      dis2001a.asp                                   #
'#  Authors:           Louise Yukari Cicalise Takeshita							 #
'#  Created:           19 Jun 2012                                               #
'#  Ended:             19 Jun 2012                                               #
'#  Last update:       19 Jun 2012                                               #
'#  Version:           1.0.0 - 19-Jun-2012                                       #
'#  Bugs:                                                                        #
'#-------------------------------------------------------------------------------#
%>

<!-- PAGE DESCRIPTION -->
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="Description" content="Allele Frequencies Website" />
<meta name="Keywords" content="HLA, KIR, frequencies, allele, disease, association" />
<link rel="shortcut icon" href="../images/favicon.ico" />
<title>The Allele Frequency Net Database [Add Disease Association Study] </title>

<!-- CSS STYLE SHEETS -->
<link rel="stylesheet" type="text/css" href="../styles/format.css" />

<!-- ROUTINES -->
<script type="text/javascript" src="../routines/dis2001b.js"> </script>

<script>

function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajaxtest.asp?filename=newName.xls",true);
xmlhttp.send();
}


</script>
    <style type="text/css">
.upload {
   border-top: 1px solid #96d1f8;
   background: #65a9d7;
   background: -webkit-gradient(linear, left top, left bottom, from(#3e779d), to(#65a9d7));
   background: -webkit-linear-gradient(top, #3e779d, #65a9d7);
   background: -moz-linear-gradient(top, #3e779d, #65a9d7);
   background: -ms-linear-gradient(top, #3e779d, #65a9d7);
   background: -o-linear-gradient(top, #3e779d, #65a9d7);
   padding: 2px 4px;
   -webkit-border-radius: 8px;
   -moz-border-radius: 8px;
   border-radius: 8px;
   -webkit-box-shadow: rgba(0,0,0,1) 0 1px 0;
   -moz-box-shadow: rgba(0,0,0,1) 0 1px 0;
   box-shadow: rgba(0,0,0,1) 0 1px 0;
   text-shadow: rgba(0,0,0,.4) 0 1px 0;
   color: white;
   font-size: 10px;
   font-family: Georgia, serif;
   text-decoration: none;
   vertical-align: middle;
   }
.upload:hover {
   border-top-color: #28597a;
   background: #28597a;
   color: #ccc;
   }
.upload:active {
   border-top-color: #1b435e;
   background: #1b435e;
   }
   </style>

</head>

<body>



<%'-------------------------------------- M A I N    F R A M E W O R K ------------------------------------%>

<div style="width:950px; margin:0 auto; padding:5px 0px 5px 0px;">

<%'-------------------------------------- B O R D ER    F R A M E W O R K ---------------------------------%>
<div style="border:1px solid #0066FF;">    

<%
'#-----------------------------#
'#       H E A D E R           #
'#-----------------------------#
%>

<div id="divGenHeader">
		<table class="table10">
           <tr>
				<td><a href="default.asp"><img src="../images/banner.gif" alt="Allele Frequencies in World Populations" /></a></td>
		  </tr>
		</table>
</div>		

<%
'#-----------------------------#
'#   PROGRAM NAME              #
'#-----------------------------#
%>
<div id="divGenProg">
	<h2>KIR and diseases &raquo; Add New Disease Association Study</h2>
</div>

<%
'#-----------------------------#
'#   INSTRUCTIONS              #
'#-----------------------------#
%>
<div id="divGenInstructions">
	<h6>Instructions: Submit Raw Data</h6><br />
	<p>Now you can submit your KIR raw genotyping data.</p>
    <p>If you want to proceed, please upload your file below.</p>
    <p>If you have not downloaded KIR raw data template at the first page, click on the "Download" link below.</p>
    <p><b>KIR_Raw_Data.xls: <a href="docs/KIR_Raw_Data.xls"><u>Download</u></a></b></p>
    <p>Follow the instructions inside the template to fill out the template.</p>
</div>

<%
'#-----------------------------#
'#   NAVIGATION OPTIONS        #
'#-----------------------------#
%>
<div id="divGenNavig">	
<h2 style="line-height:25px"><span style="color:#999">Demographic Data &raquo; Frequency Data &raquo; </span>Raw Data &raquo; <span style="color:#999">Confirmation</span></h2>
</div>


<br><br>
	<div id="divGenDetail">
	<table class="table11">
<tr>
<td>
	<table class="table04">
    
<!-- Instructions -->
<tr><td>&nbsp;&nbsp;&nbsp;</td><td><h3>Upload KIR Raw Data:</h3></td></tr>
<tr><td></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;</td><td style="border-top:2px solid #36F; border-bottom:2px solid #36F; padding:10px 10px 10px 10px">
<%
Dim diagnostics
Dim nameoffile
Dim vars
if Request.ServerVariables("REQUEST_METHOD") <> "POST" then
    diagnostics = TestEnvironment()
    if diagnostics<>"" then
        response.write "<div style=""margin-left:20; margin-top:30; margin-right:30; margin-bottom:30;"">"
        response.write diagnostics
        response.write "<p>After you correct this problem, reload the page.</p>"
        response.write "</div>"
    end if
else
    nameoffile = SaveFiles()
	If ValRawData() = true Then
		Response.Write("<form name='frmSend' method='POST' enctype='multipart/form-data' accept-charset='utf-8' action='dis_confirm.asp'>")
		Response.Write("<input type='hidden' name='filename' id='filename' value='" & nameoffile & "' />")
		Response.Write (SaveVars())
		Response.Write("<p><b>File was successfully uploaded!</b></p>")
		Response.Write("<i>Click on &quot;Next&quot; to continue.</i>&nbsp;&nbsp;&nbsp;")
		Response.Write("<input type='submit' name='next' value='Next' />")
	Else
		Response.Write("<form name='frmSend' method='POST' enctype='multipart/form-data' accept-charset='utf-8'>")
		Response.Write (SaveVars())
		Response.Write("<input name='attach1' id='attach1' type='file' size=35 onchange='TryAgain();'>&nbsp;&nbsp;&nbsp;")
		Response.Write("<input style='margin-top:4' class='upload' name='upload' type='button' value='Upload' onclick='return fctUpload();'>")
	End If	
end if

%>
</td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;</td><td><div style="font-size:7px">"Powered by <A HREF="http://www.freeaspupload.net/" style="color:black">Free ASP Upload</A></div></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;</td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;</td></tr>

        </div>
        </div>
    </table>		
	</td>
	</tr>
</table>
</form>	
</div>

<br><br>
<%'#---------------------------------------------------- END FORM --------------------------------------------------%>
</div>
<%'--------------------------------------#            END BORDER FRAMEWORK       #----------------------------------%>

<%'------------------------------------------#           FOOTER             #--------------------------------------%>
<div id="divGenFooter" align="center">
<label style="background-color:#b8cce4; border:solid 1px #006699; color:#006699; width:200; font:normal 11px Arial;">
 &copy;2012 Allele Frequencies Website.     </label>   <br /><br />
<b>Allele frequency net:</b> a database and online repository for immune gene frequencies in worldwide populations. <br />
Gonzalez-Galarza FF, Christmas S, Middleton D and Jones AR
<i>Nucleic Acid Research 2011, 39, D913-D919.</i><br />
Liverpool, U.K. <a href="mailto:support@allelefrequencies.net"><br /><br />support@allelefrequencies.net</a>
<br /><br />
<a href="http://validator.w3.org/check?uri=referer" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a>
</div>
<%'------------------------------------------#            END FOOTER       #--------------------------------------%>
</div>
<%'--------------------------------------#            END MAIN FRAMEWORK       #----------------------------------%>
</body>
</html>	
